package cn.htu.edu.service.impl;

import cn.htu.edu.common.ResponseHelper;
import cn.htu.edu.common.ResponseModel;
import cn.htu.edu.entity.Rname;
import cn.htu.edu.mapper.RnameMapper;
import cn.htu.edu.payload.RAge;
import cn.htu.edu.service.IRnameService;
import cn.htu.edu.utils.RandomName;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.security.SecureRandom;
import java.util.Random;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dakai
 * @since 2024-01-11
 */
@Service
public class RnameServiceImpl extends ServiceImpl<RnameMapper, Rname> implements IRnameService {

    @Override
    public ResponseModel addName(RAge request) {
        Snowflake snowflake = IdUtil.getSnowflake(1, 1);
        Rname rname = new Rname();
        RandomName randomName = new RandomName();
        rname.setId(snowflake.nextId())
                .setName(randomName.fetName())
                .setAge(request.getAge());
        this.save(rname);
        return ResponseHelper.buildResponseModel("添加成功");
    }
}
